//
//  BulletModelInfo.m
//  SpaceStorm
//
//  Created by 祥 雍 on 13-5-26.
//  Copyright (c) 2013年 __MyCompanyName__. All rights reserved.
//
//  弹药模型表的信息类//缺宽和高

#import "BulletModelInfo.h"
#import "Variable.h"

@implementation BulletModelInfo

@synthesize bulletModelId = _bulletModelId;
@synthesize bulletBig = _bulletBig;
@synthesize bulletMid = _bulletMid;
@synthesize bulletSmall = _bulletSmall;
@synthesize level = _level;
@synthesize groupId = _groupId;
@synthesize name = _name;
@synthesize width = _width;
@synthesize height = _height;
@synthesize anchorPoint = _anchorPoint;
@synthesize fromEffect = _fromEffect;
@synthesize movingEffect = _movingEffect;
@synthesize toEffect = _toEffect;

+(id) infoWithTbxml:(TBXMLElement *)tbxml
{
    return [[[self alloc] initWithTbxml:tbxml] autorelease]; 
}

-(id) initWithTbxml:(TBXMLElement *)tbxml
{
    self = [super init]; 
	
	if (self!= nil) 
    {
        //弹药模型id	
        self.bulletModelId = [[TBXML valueOfAttributeNamed:@"bulletModelId" forElement:tbxml] intValue];
        if(showXMLLog == YES) CCLOG(@"弹药模型id:%d", self.bulletModelId);
        
        //弹药大类
        self.bulletBig = [[TBXML valueOfAttributeNamed:@"bulletBig" forElement:tbxml] intValue];
        if(showXMLLog == YES) CCLOG(@"弹药大类:%d", self.bulletBig);
        
        //弹药中类	
        self.bulletMid = [[TBXML valueOfAttributeNamed:@"bulletMid" forElement:tbxml] intValue];
        if(showXMLLog == YES) CCLOG(@"弹药中类:%d", self.bulletMid);
        
        //弹药细类	
        self.bulletSmall = [[TBXML valueOfAttributeNamed:@"bulletSmall" forElement:tbxml] intValue];
        if(showXMLLog == YES) CCLOG(@"弹药细类:%d", self.bulletSmall);
        
        //科技等级	
        self.level = [[TBXML valueOfAttributeNamed:@"level" forElement:tbxml] intValue];
        if(showXMLLog == YES) CCLOG(@"科技等级:%d", self.level);
        
        //小组编号	
        self.groupId = [[TBXML valueOfAttributeNamed:@"groupId" forElement:tbxml] intValue];
         if(showXMLLog == YES) CCLOG(@"小组编号:%d", self.groupId);
        
        //弹药	
        self.name = [TBXML valueOfAttributeNamed:@"name" forElement:tbxml];
        if(showXMLLog == YES) CCLOG(@"弹药:%@", self.name);
        
        //模型的宽
        self.width = [[TBXML valueOfAttributeNamed:@"width" forElement:tbxml] floatValue];
        if(showXMLLog == YES) CCLOG(@"width:%f", self.width);
        
        //模型的高
        self.height = [[TBXML valueOfAttributeNamed:@"height" forElement:tbxml] floatValue];
        if(showXMLLog == YES) CCLOG(@"height:%f", self.height);
        
        //重心坐标（导弹用）
        NSString * x;
        NSString * y;
        NSArray *array;
        NSString * anchorPoint = [TBXML valueOfAttributeNamed:@"anchorPoint" forElement:tbxml];
        if([anchorPoint isEqualToString: @"0"] == NO)//非0保护
        {
            array = [anchorPoint componentsSeparatedByString:@","]; 
            x = [array objectAtIndex:0];
            y = [array objectAtIndex:1];
            self.anchorPoint = ccp([x floatValue] / self.width, (1 - [y floatValue] / self.height));
            if(showXMLLog == YES) CCLOG(@"重心坐标（导弹用:%f,%f", [x floatValue], [y floatValue]);
        }
        else
        {
            self.anchorPoint = CGPointZero;
        }
        
        //弹药发射特效	
        self.fromEffect = [TBXML valueOfAttributeNamed:@"fromEffect" forElement:tbxml];
        if(showXMLLog == YES) CCLOG(@"弹药发射特效:%@", self.fromEffect);
        
        //弹药弹道特效	
        self.movingEffect = [TBXML valueOfAttributeNamed:@"movingEffect" forElement:tbxml];
        if(showXMLLog == YES) CCLOG(@"弹药弹道特效:%@", self.movingEffect);
        
        //弹药着弹特效
        self.toEffect = [TBXML valueOfAttributeNamed:@"toEffect" forElement:tbxml];
        if(showXMLLog == YES) CCLOG(@"弹药着弹特效:%@", self.toEffect);
    }
    
    return self;
}
@end
